package com.d3works.apps.supplychain.service;

import com.d3works.apps.base.db.Company;
import com.d3works.apps.base.db.Product;
import com.d3works.apps.stock.db.StockLocation;
import com.d3works.apps.supplychain.db.Mrp;
import com.d3works.exception.D3worksException;
import java.time.LocalDate;
import java.util.concurrent.Callable;

public interface MrpService extends Callable<Mrp> {

  /**
   * To call before using it as a callable.
   *
   * @param mrp a mrp managed by hibernate
   */
  public void setMrp(Mrp mrp);

  public void setTenantId(String tenantId);

  public void setTenantHost(String tenantHost);

  public void runCalculation(Mrp mrp) throws D3worksException;

  public void generateProposals(Mrp mrp, boolean isProposalsPerSupplier) throws D3worksException;

  public void reset(Mrp mrp);

  public void undoManualChanges(Mrp mrp);

  /**
   * Search for the end date of the mrp. If the end date field in mrp is blank, search in the lines
   * the last date.
   *
   * @param mrp
   * @return the mrp end date
   */
  public LocalDate findMrpEndDate(Mrp mrp);

  public Mrp createProjectedStock(
      Mrp mrp, Product product, Company company, StockLocation stockLocation)
      throws D3worksException;

  /**
   * Called when an exception occurred during the mrp computation. Save the exception message.
   *
   * @param mrp a mrp after computation
   * @param e the exception thrown during the computation
   */
  void saveErrorInMrp(Mrp mrp, Exception e);

  void massUpdateProposalToProcess(Mrp mrp, boolean proposalToProcess);

  /**
   * Methods that checks if mrp is currenctly started.
   *
   * @param mrp
   * @return
   * @throws D3worksException
   */
  boolean isOnGoing(Mrp mrp) throws D3worksException;
}
